package com.zxu.test.header;

import android.view.View;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zxu.test.studyapp.R;
import com.zxu.test.util.DoubleClickUtils;
import com.zxu.test.util.Event;

public class CommonTipHeaderViewModel extends ViewModel {

    private final MutableLiveData<String> title = new MutableLiveData<>();
    private final MutableLiveData<Event<Object>> backEvent = new MutableLiveData<>();
    private final MutableLiveData<Event<Object>> tipEvent = new MutableLiveData<>();
    private final MutableLiveData<String> tip = new MutableLiveData<>();

    public MutableLiveData<String> getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title.setValue(title);
    }

    public MutableLiveData<String> getTip() {
        return tip;
    }

    public void setTip(String tip) {
        this.tip.setValue(tip);
    }

    public MutableLiveData<Event<Object>> getTipEvent() {
        return tipEvent;
    }

    public MutableLiveData<Event<Object>> getBackCommand() {
        return backEvent;
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ivBack:
                if (!DoubleClickUtils.isFastDoubleClick(R.id.ivBack))
                backEvent.setValue(new Event<>(""));
                break;
            case R.id.tvTip:
                if (!DoubleClickUtils.isFastDoubleClick(R.id.tvTip))
                    tipEvent.setValue(new Event<>(""));
                break;
        }
    }
}
